package xyz.xpman.prisonerfitness.config;

import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;

public class QQGroupConfig {
    private static final String ID = "id";
    private static final String KEY = "key";
    private static final String PASSWD = "passwd";
    private static final String AVAILABLE = "available";

    private final String id;
    private final String key;
    private final String passwd;
    private final boolean available;

    public QQGroupConfig(String id, String key, String passwd, boolean available) {
        this.id = id;
        this.key = key;
        this.passwd = passwd;
        this.available = available;
    }

    public String getId() {
        return id;
    }

    public String getKey() {
        return key;
    }

    public String getPasswd() {
        return passwd;
    }

    public boolean getIsAvailable() {
        return available;
    }

    public static QQGroupConfig by(@NotNull String id,
                                   @NotNull String key,
                                   String passwd,
                                   boolean available) {
        if (id.isEmpty() || key.isEmpty()) {
            return null;
        }

        return new QQGroupConfig(id, key, passwd, available);
    }

    public static QQGroupConfig byJson(@NotNull JSONObject json) throws JSONException {
        final String id = json.getString(ID);
        final String key = json.getString(KEY);
        final String passwd = json.getString(PASSWD);
        final boolean available = json.getBoolean(AVAILABLE);

        return by(id, key, passwd, available);
    }

}
